<template>
    <div class="header-box">
        <el-header>
            <el-container>
                <div class="nav-left" :style="{'width':(isCollapse == false ? '210px':'64px')}">{{isCollapse == false ? '后台管理': 'lv'}}</div>
                <div class="cenflex nav-right">
                    <div class="flex" style="align-items:center;">
                        <div @click="isCollapse = !isCollapse" class="marginRig20">
                            <icon-svg name="zhedie" style="color:#333333;vertical-align:middle;" ></icon-svg>
                        </div>
                        <div style="display:inline-block;vertical-align:middle;" v-if="isnavoff == true">
                            <el-breadcrumb separator="/">
                                <transition-group name="fade">
                                    <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.meta.title">
                                        <span v-if="item.redirect==='noredirect'||index==levelList.length-1" class="no-redirect">{{item.meta.title}}</span>
                                        
                                        <router-link :to="item.redirect||item.path">{{item.meta.title}}</router-link>
                                    </el-breadcrumb-item>
                                </transition-group>
                            </el-breadcrumb>
                        </div>
                    </div>
                    <div class="cenflex">
                        <color-picker class="marginRig15" v-if="mainColorFlag == true"></color-picker>
                        <div title="全屏" @click="full()" class="marginRig10" v-if="fullscreenFlag == true">
                            <icon-svg name="fullscreen" style="color:#333333;font-size:18px;vertical-align:middle;" class="marginRig10"></icon-svg>
                        </div>
                        <div title="导航切换" class="marginRig20" @click="isnavoff = !isnavoff" v-if="navToggleFlag == true">
                            <icon-svg name="navtoggle" style="font-size:25px;vertical-align:middle;"></icon-svg>
                        </div>
                        <el-dropdown>
                            <span class="el-dropdown-link">
                                <img class="cus-ava" src="../../assets/img/avatar.jpg" />{{userName}}
                                <i class="el-icon-arrow-down el-icon--right"></i>
                            </span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item @click.native="getHome()">首页</el-dropdown-item>
                                <el-dropdown-item>个人信息</el-dropdown-item>
                                <el-dropdown-item @click.native="drawer = true">界面设置</el-dropdown-item>
                                <el-dropdown-item @click.native="logoutHandle()">退出系统</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </div>
                </div>
            </el-container>
        </el-header>
        <!-- 界面设置弹框 -->
        <el-drawer title="界面设置" :visible.sync="drawer" :direction="direction" :append-to-body="true">
            <div class="control-box">
                <div>
                    <span>全屏:</span>
                    <el-switch v-model="fullscreenFlag">
                    </el-switch>
                </div>
                <div>
                    <span>主题色:</span>
                    <el-switch v-model="mainColorFlag">
                    </el-switch>
                </div>
                <div>
                    <span>导航主题:</span>
                    <el-switch v-model="navToggleFlag">
                    </el-switch>
                </div>
            </div>
        </el-drawer>
    </div>
</template>
<script>
import { fullscreenToggel } from "../../utils/tools";
import colorPicker from "../../components/theme-picker"
export default {
    components: {
        colorPicker
    },
    data() {
        return {
            color: "#ffffff",
            userInfo: {},
            userName: "",
            drawer: false,
            direction: 'rtl',
            levelList: [
                {
                    path: "/sys-user",
                    meta: {
                        title: "首页"
                    }
                },
                {
                    path: "/menu-list",
                    meta: {
                        title: "菜单"
                    }
                }
            ],

        }
    },
    created() {
       
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'));
        this.userName = this.userInfo.userName;
    },
    computed: {
        isCollapse: {
            get() {
                return this.$store.state.common.isCollapse
            },
            set(val) {
                this.$store.commit('updateSidebarFold', val)
            }
        },
        isnavoff: {
            get() {
                return this.$store.state.common.isnavoff
            },
            set(val) {
                this.$store.commit('updateisnavoff', val)
            }
        },
        fullscreenFlag: {
            get() {
                return this.$store.state.common.fullscreenFlag;
            },
            set(val) {
                this.$store.commit('updatefullscreenFlag', val)
            }
        },
        mainColorFlag: {
            get() {
                return this.$store.state.common.mainColorFlag;
            },
            set(val) {
                this.$store.commit('updatemainColorFlag', val)
            }
        },
        navToggleFlag: {
            get() {
                return this.$store.state.common.navToggleFlag;
            },
            set(val) {
                this.$store.commit('updatenavToggleFlag', val)
            }
        },
    },
    methods: {
        isreduce() { //控制菜单是否折叠
            this.$store.commit('isasideNav');
        },
        full() { //控制是否全屏
            fullscreenToggel()
        },
        getHome() {
            this.$router.push({ path: '/home' });
        },
        // navupdate() {
        //     console.log(1111)
        //     this.isnavToggle = !this.isnavToggle;

        // },
        logoutHandle() { //退出系统
            this.$confirm(`确定进行[退出]操作?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                sessionStorage.clear();
                this.$router.push({ name: 'login' });
            }).catch(() => { })
        },

    },

}
</script>
<style lang="scss">
.header-box {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    line-height: 60px;
    background: #ffffff;
    z-index: 10;
    border-bottom: 1px solid #e6e6e6;
    .el-header {
        padding: 0 10px 0 0;
    }
}
.nav-left {
    text-align: center;
    transition: inline-block 0.3s, left 0.3s, width 0.3s, margin-left 0.3s,
        font-size 0.3s;
    // transition: 0.31s;
    -webkit-transition: inline-block 0.3s, left 0.3s, width 0.3s,
        margin-left 0.3s, font-size 0.3s;
}
.nav-right {
    flex: 1;
    margin-left: 10px;
    align-items: center;
    justify-content: space-between;
}
.el-dropdown-link {
    cursor: pointer;
    color: #333333;
}
.el-icon-arrow-down {
    font-size: 12px;
}
.cus-ava {
    margin-right: 5px;
    display: inline-block;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    vertical-align: middle;
    // border: 1px solid;
}
.full-box {
    display: inline-block;
}
.full-box-active {
    display: none;
}
.el-drawer__header > span {
    outline: none;
}
.control-box {
    padding: 0 10px;
}
.control-box > div {
    margin: 15px auto 0;
}
.control-box > div > span {
    display: inline-block;
    width: 80px;
    text-align: right;
}
</style>